package com.posti.core.geocoding;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class GeocodingResult {
  private List<GeocodingLocation> locations;

  public GeocodingResult() {
    locations = new LinkedList<GeocodingLocation>();
  }

  public void addLocation(GeocodingLocation location) {
    locations.add(location);
  }

  public void addAllLocations(List<GeocodingLocation> moreLocations) {
    locations.addAll(moreLocations);
  }

  public void removeLocation(GeocodingLocation location) {
    locations.remove(location);
  }

  public List<GeocodingLocation> getLocations() {
    return Collections.unmodifiableList(locations);
  }

  public Iterator<GeocodingLocation> iterateLocations() {
    return this.getLocations().iterator();
  }

  public boolean isUniquelyDeterminedLocation() {
    return locations.size() == 1;
  }

  public boolean isUndeterminedLocation() {
    return locations.size() == 0;
  }

  public GeocodingLocation getLocation() {
    if (!this.isUniquelyDeterminedLocation())
      throw new RuntimeException(); //TODO Exception handling

    return locations.get(0);
  }
}
